package com.bluesky.jwf.component.validator;


public class RegularExpressionValidator extends StringValidator {
	private String regularExpression;

	public RegularExpressionValidator() {

	}

	@Override
	public void init(String html) {

		super.init(html);
		setMessage("a regular express");
	}

	@Override
	public void validate() {
		String s = stringField.getString();
		if (s == null || s.trim().isEmpty()) {
			setResult(true);
			return;
		}
		if (s.matches(regularExpression))
			setResult(true);
		else
			setResult(false);

	}

	public String getRegularExpression() {
		return regularExpression;
	}

	public void setRegularExpression(String regularExpression) {
		this.regularExpression = regularExpression;
	}

}
